home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / winftp.zip / WNFTPSRC.ZIP / WS_HOST.C < prev    next >
C/C++ Source or Header  |  1994-01-07  |  51KB  |  1,401 lines

  1. #include "ws_glob.h"
  2. #include "winftp.h"
  3. #include <stdlib.h>  
  4. #include <io.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. #define MAXHOSTS 20
  9. #define GET_CBOX_INDEX(wnd,id,str) (int) SendDlgItemMessage (wnd, id, CB_SELECTSTRING, (WPARAM) 0, (LPARAM) (LPCSTR) str)
  10.  
  11. LPVIEWERCFG lpViewer;
  12. LPHOSTCONFIG lpHostCfg;
  13. HANDLE hHostCfg;
  14.  
  15. BOOL bSaveUID=FALSE;
  16. BOOL bSavePWD=FALSE;
  17. BOOL bSaveDir;
  18.  
  19. char szCrypt[160];
  20.  
  21. LPSTR lpApp          = "winftp";
  22. LPSTR szUndecipher   = "undecipherable";
  23. LPSTR szAnony        = "anonymous";
  24. LPSTR szProfHostName = "HostName";
  25. LPSTR szProfUserID   = "UserID";
  26. LPSTR szProfHostType = "HostType";
  27. LPSTR szProfTimeOut  = "TimeOut";
  28. LPSTR szProfMailAddr = "MailAddr";
  29. LPSTR szProfViewer   = "Viewer";
  30. LPSTR szProfTempDir  = "TempDir";
  31. LPSTR szProfAutoStart= "AutoStart";
  32. LPSTR szProfRetain   = "Retain";
  33. LPSTR szProfConfigNum= "ConfigNum";
  34. LPSTR szProfFlags    = "Flags";
  35. LPSTR szProfConfig   = "Config";
  36. LPSTR szProfPass     = "Pass";
  37. LPSTR szProfDir      = "Dir";
  38. LPSTR szProfScript   = "Script";
  39. LPSTR szProfFireWall = "FireWall";
  40. LPSTR szProfLogFlag  = "LogFlag";
  41. LPSTR szProfLogFile  = "LogFile";
  42. LPSTR szProfDblClk   = "DblClk";
  43. LPSTR szProfViewPgm  = "Viewer";
  44. LPSTR szProfViewTyp  = "Ext";
  45. LPSTR szProfViewXfer = "Xfer";
  46. LPSTR szProfSaveDir  = "Save";
  47. LPSTR szProfViewCount= "ViewerCount";
  48.  
  49. LPSTR szProfFireWallHost = "FireWallHost";
  50. LPSTR szProfFireWallUser = "FireWallUser";
  51. LPSTR szProfFireWallPass = "FireWallPass";
  52.  
  53. LPSTR lpHostTypes[] = { "AutoDetect",  "Unix",    "IBM VM",  "VMS/Multinet",
  54.                         "VMS/UCX", "FTP Software PCTCP", "CUTCP/NCSA", 
  55.                         "NOS/KA9Q", "WinQVT/Net", "IBMPC TCP/IP",
  56.                         "CHAMELEON", "SuperTCP", "SI NT/FTPD", "IBM MVS", 
  57.                         "UniSys 5000" };
  58.  
  59. int nHostTypes = sizeof (lpHostTypes) / sizeof (char *);
  60.  
  61. LPSTR lpAcctTypes[] = { "Account not needed", "Account Type 1", 
  62.                         "Account Type 2", "Account Type 3", 
  63.                         "Account Type 4" };
  64.  
  65. extern BOOL bHELP;
  66.  
  67. //******************************************************************************
  68. //******************************************************************************
  69. LPSTR GetHostName (int nI)
  70. {
  71.   if (lpHostCfg==NULL) return NULL;
  72.   if (nI>=nCfgNum) return NULL;
  73.   return lpHostCfg[nI].szHostName;
  74. }
  75.  
  76. char szTmpHostType[40];
  77.  
  78. //******************************************************************************
  79. //******************************************************************************
  80. LPSTR GetHostType (int nI)
  81. {
  82.   char szSection[200];
  83.   int nType;
  84.   
  85.   if (lpHostCfg==NULL) return NULL;
  86.   if (nI>=nCfgNum) return NULL;
  87.   wsprintf (szSection, "%s:%s", lpApp, lpHostCfg[nI].szConfig);
  88.   GetPrivateProfileString (szSection, szProfHostType, NULL, szTmpHostType, 29, szIniFile);
  89.   if (!isdigit (szTmpHostType[0])) return (LPSTR) szTmpHostType;
  90.   nType = atoi (szTmpHostType); 
  91.   if (nType==LB_ERR) nType = HOST_AUTO;
  92.   return lpHostTypes[nType];
  93. }
  94.  
  95. //******************************************************************************
  96. //******************************************************************************
  97. LPSTR GetHostTypeValue (int nI)
  98. {
  99.   if (nI>=nHostTypes) return NULL;
  100.   return lpHostTypes[nI];
  101. }
  102.  
  103. //******************************************************************************
  104. // this encryption is not secure nor is it intended to be
  105. // this is just to keep the password from being plain text
  106. // in the ini file.  I'd really recommend people don't save
  107. // their passwords
  108. //******************************************************************************
  109. LPSTR EnCrypt(LPSTR userid,LPSTR passwd)
  110. {
  111.   int nIndex;
  112.   if(lstrcmp(userid,szAnony)==0)
  113.     return(passwd);
  114.   szCrypt[0]=0;
  115.   for(nIndex=0;nIndex<lstrlen(passwd);nIndex++) 
  116.   {
  117.     wsprintf(&szCrypt[nIndex*2],"%02X",
  118.       ((char)passwd[nIndex])+nIndex);
  119.   }
  120.   return(szCrypt);
  121. }
  122.  
  123. //******************************************************************************
  124. //******************************************************************************
  125. int unhex(char c) 
  126. {
  127.   if(c>'9') return(c-'7');
  128.   return (c-'0');
  129. }
  130.  
  131. //******************************************************************************
  132. //******************************************************************************
  133. LPSTR DeCrypt(LPSTR userid,LPSTR passwd)
  134. {
  135.   int nIndex;
  136.   if(lstrcmp(userid,szAnony)==0)
  137.     return(passwd);
  138.   szCrypt[0]=0;
  139.   for(nIndex=0;nIndex<lstrlen(passwd);nIndex+=2) 
  140.   {
  141.     (BYTE)szCrypt[nIndex/2]=
  142.       ((unhex(passwd[nIndex])*16)+
  143.        unhex(passwd[nIndex+1]))-(nIndex/2);
  144.     szCrypt[nIndex/2+1]=0;
  145.   }
  146.   return(szCrypt);
  147. }
  148.  
  149. //******************************************************************************
  150. //******************************************************************************
  151. void InitConfigLists (HWND hDlg)
  152. {
  153.   LRESULT nI;
  154.   int nIndex;
  155.  
  156.   SendDlgItemMessage (hDlg,DLG_EDT_CONFIG, CB_RESETCONTENT, 0, 0L);
  157.   SendDlgItemMessage (hDlg,DLG_EDT_HOST,   CB_RESETCONTENT, 0, 0L);
  158.   if (nCfgNum==0) return;
  159.   for (nIndex=0; nIndex<nCfgNum; nIndex++)
  160.   {
  161.     if (lpHostCfg[nIndex].szConfig[0]!=0)
  162.        SendDlgItemMessage (hDlg, DLG_EDT_CONFIG, CB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpHostCfg[nIndex].szConfig);
  163.     if (lpHostCfg[nIndex].szHostName[0]!=0)
  164.     {
  165.       nI = SendDlgItemMessage (hDlg, DLG_EDT_HOST, CB_FINDSTRINGEXACT, (WPARAM) -1, (LPARAM)(LPCSTR) lpHostCfg[nIndex].szHostName);
  166.       if (nI==CB_ERR) SendDlgItemMessage (hDlg,DLG_EDT_HOST,CB_ADDSTRING,0,(LPARAM)(LPCSTR) lpHostCfg[nIndex].szHostName);
  167.     }
  168.   }
  169.   SendDlgItemMessage (hDlg, DLG_EDT_CONFIG, WM_SETTEXT, 0, (LPARAM) (LPCSTR) szConfig);
  170.   SendDlgItemMessage (hDlg, DLG_EDT_HOST,   WM_SETTEXT, 0, (LPARAM) (LPCSTR) szRemoteHost);
  171.   for (nI=0; nI<5; nI++)
  172.   {
  173.     SendDlgItemMessage (hDlg, DLG_ACCOUNTTYPE, CB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpAcctTypes[nI]);
  174.   }
  175.   SendDlgItemMessage (hDlg, DLG_ACCOUNTTYPE, CB_SELECTSTRING, 0, (LPARAM)(LPCSTR) lpAcctTypes[nAcctType]);
  176. }
  177.  
  178. //******************************************************************************
  179. //******************************************************************************
  180. SetDefaultDlgStuff(HWND hDlg, int nIndex) 
  181. {
  182.   char szSection[80], szHostType[30], szFireWall[10];
  183.   HOSTINFO Host;
  184.   
  185.   wsprintf (szSection, "%s:%s", lpApp, lpHostCfg[nIndex].szConfig);
  186.   memset (&Host, '\0', sizeof (HOSTINFO));
  187.   memset (szHostType, '\0', 30);
  188.   memset (szFireWall, '\0', 10);
  189.   GetPrivateProfileString (szSection, szProfUserID,   NULL, Host.szUserID,   79, szIniFile);
  190.   GetPrivateProfileString (szSection, szProfPass,     NULL, Host.szPassword, 79, szIniFile);
  191.   GetPrivateProfileString (szSection, szProfDir,      NULL, Host.szInitDir,  79, szIniFile);
  192.   GetPrivateProfileString (szSection, szProfScript,   NULL, Host.szScript,   79, szIniFile);
  193.   GetPrivateProfileString (szSection, szProfHostType, NULL, szHostType,      29, szIniFile);
  194.   GetPrivateProfileString (szSection, szProfFireWall, NULL, szFireWall,       9, szIniFile);
  195.  
  196.   Host.nTimeOut = GetPrivateProfileInt (szSection, szProfTimeOut,  65, szIniFile);
  197.   Host.bSaveDir = GetPrivateProfileInt (szSection, szProfSaveDir,   0, szIniFile);
  198.   Host.bFireWall= (lstrcmpi (szFireWall, "Yes")==0)||(lstrcmp (szFireWall, "1")==0);
  199.   switch (isdigit (szHostType[0]))
  200.   {
  201.     case 0 : Host.nType = GET_CBOX_INDEX (hDlg, DLG_HOST_CBHOSTTYPE, szHostType); break;
  202.     default: Host.nType = atoi (szHostType); 
  203.   }
  204.   if (Host.nType==LB_ERR) Host.nType = HOST_AUTO;
  205.   Host.nType = __max (HOST_AUTO, __min (Host.nType, (nHostTypes-1)));
  206.   
  207.   SetDlgItemText (hDlg, DLG_EDT_SCRIPT, Host.szScript);
  208.   SetDlgItemText (hDlg, DLG_EDT_USERID, (Host.szUserID[0]!='\0')?Host.szUserID:szUserID);
  209.   SetDlgItemText (hDlg, DLG_EDT_PASSWD, DeCrypt (Host.szUserID, Host.szPassword));
  210.   GET_CBOX_INDEX (hDlg, DLG_HOST_CBHOSTTYPE, lpHostTypes[Host.nType]);
  211.   
  212.   CheckDlgButton (hDlg, DLG_HOST_SAVEDIR, Host.bSaveDir);
  213.   CheckDlgButton (hDlg, DLG_HOST_FIREWALL, Host.bFireWall);
  214.   SetDlgItemText (hDlg, DLG_HOST_DIR, Host.szInitDir);
  215.   SetDlgItemInt  (hDlg, DLG_HOST_TIMEOUT, Host.nTimeOut, FALSE);
  216.   return 0;
  217. }
  218.  
  219. //******************************************************************************
  220. //******************************************************************************
  221. SetDefaultHostStuff (HWND hDlg,LPSTR szRHost) 
  222. {
  223.   int nIndex;
  224.  
  225.   if (nCfgNum<=0) return FALSE;
  226.   for (nIndex=0; nIndex<nCfgNum; nIndex++)
  227.   {
  228.     if(lstrcmp (szRHost, lpHostCfg[nIndex].szHostName)==0) 
  229.     {
  230.       SetDlgItemText (hDlg, DLG_EDT_CONFIG, lpHostCfg[nIndex].szConfig);
  231.       SetDefaultDlgStuff (hDlg, nIndex);
  232.       break;
  233.     }
  234.   }
  235.   return TRUE;
  236. }
  237.  
  238. //******************************************************************************
  239. //******************************************************************************
  240. SetDefaultConfigStuff (HWND hDlg, LPSTR szConfig) 
  241. {
  242.   int nIndex;
  243.  
  244.   if (nCfgNum<=0) return FALSE;
  245.   for (nIndex=0; nIndex<nCfgNum; nIndex++)
  246.   {
  247.     if(lstrcmp (szConfig, lpHostCfg[nIndex].szConfig)==0) 
  248.     {
  249.       SetDlgItemText (hDlg,DLG_EDT_HOST, lpHostCfg[nIndex].szHostName);
  250.       SetDefaultDlgStuff (hDlg, nIndex);
  251.     }
  252.   }
  253.   return TRUE;
  254. }
  255.  
  256. //********************************************************************
  257. //********************************************************************
  258. void WriteConfig (int nIndex)
  259. {
  260.   char szSection[100];
  261.   
  262.   wsprintf (szString, "CFG%d", nIndex);
  263.   WritePrivateProfileString (lpApp, szString, szConfig, szIniFile);
  264.  
  265.   wsprintf (szSection, "%s:%s", lpApp, szConfig);
  266.   WritePrivateProfileString (szSection, szProfHostName, szRemoteHost, szIniFile);
  267.   if (szUserID[0]!=0) 
  268.   {
  269.     WritePrivateProfileString (szSection, szProfUserID, szUserID, szIniFile);
  270.     if (szPassWord[0]!=0) 
  271.     {
  272.       WritePrivateProfileString (szSection, szProfPass, EnCrypt (szUserID, szPassWord), szIniFile);
  273.     }
  274.   }
  275.   WritePrivateProfileString (szSection, szProfDir,      szInitDir, szIniFile);
  276.   WritePrivateProfileString (szSection, szProfScript,   szScript,  szIniFile);
  277.   WritePrivateProfileString (szSection, szProfFireWall, bFireWall?"Yes":"No",  szIniFile);
  278.   WritePrivateProfileString (szSection, szProfHostType, lpHostTypes[nHostType], szIniFile);
  279.  
  280.   wsprintf (szMsgBuf, "%u", uiTimeOut / 1000);
  281.   WritePrivateProfileString (szSection, szProfTimeOut, szMsgBuf, szIniFile);
  282.   WritePrivateProfileString (szSection, szProfSaveDir, bSaveDir?"1":"0", szIniFile);
  283. }
  284.  
  285. //********************************************************************
  286. //  Set the Transfer type for View operations
  287. //********************************************************************
  288. void SetViewTyp (int nI, char nTyp)
  289. {
  290.   if (nI>=nViewNum) return;
  291.   if (lpViewer==NULL) return;
  292.   lpViewer[nI].nTyp = nTyp;
  293. }
  294.  
  295. //********************************************************************
  296. //  Return a Transfer type 
  297. //********************************************************************
  298. char GetViewTyp (int nI)
  299. {
  300.   if (nI>=nViewNum) return TYPE_A;
  301.   if (lpViewer==NULL) return TYPE_A;
  302.   return lpViewer[nI].nTyp;
  303. }
  304.  
  305. //********************************************************************
  306. //  Return a pointer to Extension 
  307. //********************************************************************
  308. LPSTR lpVuExt (int nI)
  309. {
  310.   if (nI>=nViewNum) return (LPSTR) "";
  311.   if (lpViewer==NULL) return (LPSTR) NULL;
  312.   return lpViewer[nI].szExt;
  313. }
  314.  
  315. //********************************************************************
  316. //  Return a pointer to Viewer
  317. //********************************************************************
  318. LPSTR lpVuPgm (int nI)
  319. {
  320.   if (nI>=nViewNum) return (LPSTR) "";
  321.   if (lpViewer==NULL) return (LPSTR) szViewer;
  322.   return lpViewer[nI].szViewer;
  323. }
  324.  
  325. //********************************************************************
  326. //  Return a pointer to Directory
  327. //********************************************************************
  328. LPSTR lpVuDir (int nI)
  329. {
  330.   if (nI>=nViewNum) return (LPSTR) NULL;
  331.   if (lpViewer==NULL) return NULL;
  332.   return lpViewer[nI].szDir;
  333. }
  334.  
  335. //********************************************************************
  336. //  ReAllocate the viewer specs buffer
  337. //********************************************************************
  338. LPSTR ReAllocViewer (int nNum)
  339. {
  340.   LPSTR lpVu;
  341.  
  342.   if (lpViewer==NULL)
  343.     lpVu = (LPSTR) GlobalAllocPtr (GHND, nNum*sizeof (VIEWERCFG));
  344.   else
  345.     lpVu = (LPSTR) GlobalReAllocPtr (lpViewer, nNum*sizeof (VIEWERCFG), GHND);
  346.   if (lpVu==NULL) return NULL;
  347.   lpViewer = (LPVIEWERCFG) lpVu;
  348.   return lpVu;
  349. }
  350.  
  351. //********************************************************************
  352. //  Convert type to string
  353. //********************************************************************
  354. LPSTR XferTypToStr (int nVal)
  355. {
  356.   switch (nVal)
  357.   {
  358.     case TYPE_I : return "I";
  359.     case TYPE_A : return "A";
  360.     default     : return "A";
  361.   }
  362.   return "A";
  363. }
  364.  
  365. //********************************************************************
  366. //  Read the Viewer Definitions
  367. //********************************************************************
  368. void ReadViewerInfo()
  369. {
  370.   char szSection[30], szBuf[160], *lp;
  371.   int nIndex, nLast;
  372.  
  373.   nViewNum  =GetPrivateProfileInt (lpApp, szProfViewCount, 0, szIniFile);
  374.   if (nViewNum==0) { lpViewer=NULL; return; };
  375.   nViewNum = __max (nViewNum, 20);
  376.   lpViewer  = (LPVIEWERCFG) GlobalAllocPtr (GHND, nViewNum * sizeof (VIEWERCFG));
  377.   wsprintf (szSection, "%s:%s", lpApp, szProfViewer);
  378.   for (nIndex=0; nIndex<nViewNum; nIndex++) 
  379.   {
  380.     wsprintf (szString,"%s%u", szProfViewPgm, nIndex+1);
  381.     GetPrivateProfileString (szSection, szString, NULL, szBuf, 155, szIniFile);
  382.     lpViewer[nIndex].nTyp = szBuf[0]=='I' ?TYPE_I:TYPE_A;
  383.     lp = strtok (szBuf+1, ",");
  384.     if (lp!=NULL) lstrcpy (lpViewer[nIndex].szExt, lp), 
  385.                   strupr (lpViewer[nIndex].szExt);
  386.     lp = strtok (NULL, ",");
  387.     if (lp!=NULL) lstrcpy (lpViewer[nIndex].szViewer, lp);
  388.     lp = strtok (NULL, ",");
  389.     if (lp!=NULL) lstrcpy (lpViewer[nIndex].szDir, lp);
  390.     if (lstrlen (lpViewer[nIndex].szViewer)>0) nLast=nIndex+1;
  391.   }
  392.   nViewNum = nLast;
  393. }
  394.  
  395. //********************************************************************
  396. //  Save the Viewer Definitions
  397. //********************************************************************
  398. void SaveViewerInfo()
  399. {
  400.   char szSection[30], szBuf[30];
  401.   int nIndex, nNum=1;
  402.   LPSTR lp1, lp2;
  403.   
  404.   if (nViewNum==0) return;
  405.   wsprintf (szSection, "%d", nViewNum);
  406.   WritePrivateProfileString (lpApp, szProfViewCount, szSection, szIniFile);
  407.   wsprintf (szSection, "%s:%s", lpApp, szProfViewer);
  408.   for (nIndex=0; nIndex<nViewNum; nIndex++) 
  409.   {
  410.     lp1 = lpVuExt (nIndex);
  411.     lp2 = lpVuPgm (nIndex);
  412.     if ((lstrlen (lp1)>0) && (lstrlen (lp2)>0))
  413.     {
  414.       wsprintf (szBuf,"%s%u", szProfViewPgm, nNum++);
  415.       wsprintf (szString, "%s,%s,%s,%s", XferTypToStr (lpViewer[nIndex].nTyp), 
  416.                  lpViewer[nIndex].szExt, lpViewer[nIndex].szViewer, 
  417.                  lpViewer[nIndex].szDir);
  418.       WritePrivateProfileString (szSection, szBuf, szString, szIniFile);
  419.     }
  420.   }
  421. }
  422.  
  423. //********************************************************************
  424. //  Load the User Info from the .ini file
  425. //********************************************************************
  426. void LoadUserInfo()
  427. {
  428.   char szSection[100];
  429.   char szLogFlag[10];
  430.   UINT flags;
  431.   int nIndex;
  432.  
  433.   GetPrivateProfileString (lpApp, szProfConfig,   "Cica.indiana", szConfig, 79, szIniFile);
  434.   GetPrivateProfileString (lpApp, szProfHostName, "ftp.cica.indiana.edu", szRemoteHost, 79, szIniFile);
  435.   GetPrivateProfileString (lpApp, szProfUserID,   "anonymous", szUserID, 80, szIniFile);
  436.   GetPrivateProfileString (lpApp, szProfMailAddr, NULL, szMailAddress, 127, szIniFile);
  437.   GetPrivateProfileString (lpApp, szProfViewer,   "notepad", szViewer, 120, szIniFile);
  438.   GetPrivateProfileString (lpApp, szProfTempDir,  "C:\\", szTempDir, 80, szIniFile);
  439.   GetPrivateProfileString (lpApp, szProfLogFile,  "C:\\WINFTP.LOG", szLogFile, _MAX_PATH, szIniFile);
  440.   GetPrivateProfileString (lpApp, szProfLogFlag,  "Off", szLogFlag, 5, szIniFile);
  441.  
  442.   GetPrivateProfileString (lpApp, szProfFireWallHost,  "", szFireWallHost, 80, szIniFile);
  443.   GetPrivateProfileString (lpApp, szProfFireWallUser,  "", szFireWallUserID, 30, szIniFile);
  444.   GetPrivateProfileString (lpApp, szProfFireWallPass,  "", szFireWallUserPass, 30, szIniFile);
  445.   lstrcpy (szFireWallUserPass, DeCrypt (szFireWallUserID, szFireWallUserPass));
  446.   
  447.   bAutoStart= GetPrivateProfileInt (lpApp, szProfAutoStart, bAutoStart, szIniFile);
  448.   bRetain   = GetPrivateProfileInt (lpApp, szProfRetain, 0, szIniFile);
  449.   bDblClkVu = GetPrivateProfileInt (lpApp, szProfDblClk, 0, szIniFile);
  450.   nCfgNum   = GetPrivateProfileInt (lpApp, szProfConfigNum, MAXHOSTS, szIniFile);
  451.   nCfgNum   = __max (nCfgNum, MAXHOSTS);
  452.   nLogFlag  = (lstrcmpi (szLogFlag, "Off")==0) ? MF_UNCHECKED : MF_CHECKED;
  453.  
  454.   flags=GetPrivateProfileInt(lpApp, szProfFlags, 64+4+1, szIniFile);
  455.   if(flags & 1) bRecvUniq=1; else bRecvUniq=0;
  456.   if(flags & 2) bStorUniq=1; else bStorUniq=2;
  457.   if(flags & 4) bBell=1; else bBell=0;
  458.   if(flags & 8) bInteractive=1; else bInteractive=0;
  459.   if(flags & 16) bVerbose=1; else bVerbose=0;
  460.   if(flags & 32) bHash=1; else bHash=2;
  461. //if(flags & 64) bSendPort=1; else bSendPort=0;
  462.   if(flags & 128) bDoGlob=1; else bDoGlob=2;
  463.   
  464.   CreateTempFileNames (szTempDir);
  465.   
  466.   lpHostCfg = (LPHOSTCONFIG) GlobalAllocPtr (GHND, nCfgNum * sizeof (HOSTCONFIG));
  467.   for (nIndex=0; nIndex<nCfgNum; nIndex++) 
  468.   {
  469.     wsprintf (szString,"CFG%u", nIndex);
  470.     GetPrivateProfileString (lpApp, szString, NULL, lpHostCfg[nIndex].szConfig, 79, szIniFile);
  471.   }
  472.   ReadViewerInfo();
  473.   for (nIndex=0; nIndex<nCfgNum; nIndex++) 
  474.   {
  475.     if (lpHostCfg[nIndex].szConfig[0]!='\0')
  476.     {
  477.       wsprintf (szSection,"%s:%s", lpApp, lpHostCfg[nIndex].szConfig);
  478.       GetPrivateProfileString (szSection, szProfHostName, NULL, lpHostCfg[nIndex].szHostName, 79, szIniFile);
  479.     } 
  480.   }
  481. }
  482.  
  483. //********************************************************************
  484. //  Save the User Info to the .ini file
  485. //********************************************************************
  486. void SaveUserInfo()
  487. {
  488.   UINT flags;
  489.   int nIndex;
  490.  
  491.   flags=((bRecvUniq==1)?1:0) +
  492. //              ((bStorUniq==1)?2:0) +
  493.                 ((bBell==1)?4:0) +
  494.                 ((bInteractive==1)?8:0)+
  495. //              ((bHash==1)?32:0) +
  496. //              ((bSendPort==1)?64:0) +
  497. //              ((bDoGlob==1)?128:0) +
  498.                 ((bVerbose==1)?16:0);
  499.  
  500.   if (lstrlen (szFireWallHost)>0)
  501.     lstrcpy (szFireWallUserPass, EnCrypt (szFireWallUserID, szFireWallUserPass));
  502.  
  503.   WritePrivateProfileString (lpApp, szProfConfig,   szConfig,     szIniFile);
  504.   WritePrivateProfileString (lpApp, szProfHostName, szRemoteHost, szIniFile);
  505.   WritePrivateProfileString (lpApp, szProfUserID,   szUserID,     szIniFile);
  506.   WritePrivateProfileString (lpApp, szProfMailAddr, szMailAddress,szIniFile);
  507.   WritePrivateProfileString (lpApp, szProfViewer,   szViewer,     szIniFile);
  508.   WritePrivateProfileString (lpApp, szProfTempDir,  szTempDir,    szIniFile);
  509.   WritePrivateProfileString (lpApp, szProfLogFile,  szLogFile,    szIniFile);
  510.   
  511.   WritePrivateProfileString (lpApp, szProfFireWallHost, szFireWallHost,     szIniFile);
  512.   WritePrivateProfileString (lpApp, szProfFireWallUser, szFireWallUserID,   szIniFile);
  513.   WritePrivateProfileString (lpApp, szProfFireWallPass, szFireWallUserPass, szIniFile);
  514.  
  515.   WritePrivateProfileString(lpApp, szProfLogFlag,  (nLogFlag==MF_UNCHECKED)?"Off":"On", szIniFile);
  516.   wsprintf(szString,"%u",bAutoStart);
  517.   WritePrivateProfileString(lpApp, szProfAutoStart,szString,    szIniFile);
  518.   wsprintf(szString,"%u",bDblClkVu);
  519.   WritePrivateProfileString(lpApp, szProfDblClk,   szString,    szIniFile);
  520.   wsprintf (szString,"%d",nCfgNum);
  521.   WritePrivateProfileString (lpApp,szProfConfigNum, szString, szIniFile);
  522.   wsprintf (szString,"%d",bRetain);
  523.   WritePrivateProfileString (lpApp,szProfRetain, szString, szIniFile);
  524.   wsprintf (szString,"%u",flags);
  525.   WritePrivateProfileString (lpApp,szProfFlags, szString, szIniFile);
  526.   for (nIndex=0; nIndex<nCfgNum; nIndex++)
  527.   {
  528.     if (lpHostCfg[nIndex].szHostName[0]!=0) 
  529.     {
  530.       wsprintf (szString, "CFG%u", nIndex);
  531.       WritePrivateProfileString (lpApp, szString, lpHostCfg[nIndex].szConfig, szIniFile);
  532.     }
  533.   }
  534.   SaveViewerInfo();
  535.  
  536.   GlobalFreePtr (lpViewer);
  537.   GlobalFreePtr (lpHostCfg);
  538. }
  539.  
  540. //******************************************************************************
  541. // Update an Existing Configuration
  542. //******************************************************************************
  543. UpdateConfig (int nIndex)
  544. {
  545.   if (nIndex>=nCfgNum) return -1;
  546.   WriteConfig (nIndex);
  547.   return 0;
  548. }
  549.  
  550. //******************************************************************************
  551. // Add a New Configuration to the Config List
  552. //******************************************************************************
  553. void ClearConfig (int nIndex)
  554. {
  555.   char szSection[100];
  556.   HOSTINFO Host;
  557.   
  558.   wsprintf (szString,"CFG%u", nIndex);
  559.   wsprintf (szSection,"%s:%s", lpApp, lpHostCfg[nIndex].szConfig);
  560.   memset (lpHostCfg+nIndex, '\0', sizeof (HOSTCONFIG));
  561.   memset (&Host, '\0', sizeof (HOSTINFO));
  562.   WritePrivateProfileString (lpApp,     szString,       Host.szConfig,   szIniFile);
  563.   WritePrivateProfileString (szSection, szProfHostName, Host.szHostName, szIniFile);
  564.   WritePrivateProfileString (szSection, szProfUserID,   Host.szUserID,   szIniFile);
  565.   WritePrivateProfileString (szSection, szProfPass,     Host.szPassword, szIniFile);
  566.   WritePrivateProfileString (szSection, szProfDir,      Host.szInitDir,  szIniFile);
  567.   WritePrivateProfileString (szSection, szProfHostType,  "0",  szIniFile);
  568.   WritePrivateProfileString (szSection, szProfTimeOut,  "65",  szIniFile);
  569. }
  570.  
  571. //******************************************************************************
  572. // Add a New Configuration to the Config List
  573. //******************************************************************************
  574. AddNewConfig()
  575. {
  576.   int nIndex;
  577.   LPHOSTCONFIG lpHost;
  578.   
  579.   for (nIndex=0; nIndex<nCfgNum; nIndex++)
  580.   {
  581.     if (lpHostCfg[nIndex].szConfig[0]=='\0') break;
  582.   }
  583.   if (nIndex==nCfgNum)
  584.   {
  585.     lpHost = (LPHOSTCONFIG) GlobalReAllocPtr (lpHostCfg, (nCfgNum+5)*sizeof (HOSTCONFIG), GHND);
  586.     if (lpHost==NULL) return -1;
  587.     else lpHostCfg = lpHost, nCfgNum+=5;
  588.   }
  589.   if (szConfig[0]=='\0') wsprintf (szConfig, "Cfg.%s", szRemoteHost);
  590.   UpdateConfig (nIndex);
  591.   return 0;
  592. }
  593.  
  594. //******************************************************************************
  595. // Given a Config Name, find its index
  596. //******************************************************************************
  597. int FindConfig (LPSTR lpConfig, BOOL bCase)
  598. {
  599.   int nIndex;
  600.  
  601.   for (nIndex=0; nIndex<nCfgNum; nIndex++)
  602.   {
  603.     switch (bCase)
  604.     {
  605.       case TRUE : if (lstrcmp  (lpHostCfg[nIndex].szConfig, lpConfig)==0) return nIndex; break;
  606.       case FALSE: if (lstrcmpi (lpHostCfg[nIndex].szConfig, lpConfig)==0) return nIndex;
  607.     }
  608.   }
  609.   return -1;
  610. }
  611.  
  612. //******************************************************************************
  613. //  Retrieve the directories associated with the configuration
  614. //******************************************************************************
  615. RetrieveDirList (HWND hWnd)
  616. {
  617.     char szCfgBuf[100];
  618.     char szDir[100], szDirSpec[10];
  619.     int nI=0, nLen;
  620.     
  621.     int nIndex = FindConfig (szConfig, TRUE);
  622.     if (nIndex==-1) return 0;
  623.     if (lstrcmpi (szRemoteHost, lpHostCfg[nIndex].szHostName)!=0) return 0;
  624.     if (!bSaveDir) return 0;
  625.     wsprintf (szCfgBuf, "%s:%s", lpApp, szConfig);
  626.     do
  627.     {
  628.         wsprintf (szDirSpec, "DIR%d", ++nI);
  629.     GetPrivateProfileString (szCfgBuf, szDirSpec, "", szDir, 95, szIniFile);
  630.     nLen=lstrlen (szDir);
  631.     if ((nLen>0) && (lstrcmp (szDir, szUndecipher)!=0))
  632.     {
  633.       SendDlgItemMessage (hWnd, LST_RDIRLST, CB_ADDSTRING, (WPARAM) 0, (LPARAM)(LPCSTR) szDir);
  634.     }
  635.     }
  636.     while (nLen>0);
  637.     return 0;
  638. }
  639.  
  640. //******************************************************************************
  641. //  Retrieve the directories associated with the configuration
  642. //******************************************************************************
  643. SaveDirList (HWND hWnd)
  644. {
  645.     char szCfgBuf[100];
  646.     char szDir[100], szDirSpec[10];
  647.     int nI=0, nJ, nMax;
  648.     
  649.     int nIndex = FindConfig (szConfig, TRUE);
  650.     if (nIndex==-1) return 0;
  651.     if (lstrcmpi (szRemoteHost, lpHostCfg[nIndex].szHostName)!=0) return 0;
  652.     if (!bSaveDir) return 0;
  653.     nMax = (int) SendDlgItemMessage (hWnd, LST_RDIRLST, CB_GETCOUNT, (WPARAM) 0, (LPARAM) 0);
  654.     if (nMax==0) return 0;
  655.     wsprintf (szCfgBuf, "%s:%s", lpApp, szConfig);
  656.     for (nI=0, nJ=1; nI<nMax; nI++)
  657.     {
  658.     SendDlgItemMessage (hWnd, LST_RDIRLST, CB_GETLBTEXT, (WPARAM) nI, (LPARAM)(LPCSTR) szDir);
  659.     if (lstrcmp (szDir, szUndecipher)!=0)
  660.     {
  661.           wsprintf (szDirSpec, "DIR%d", nJ++);
  662.       WritePrivateProfileString (szCfgBuf, szDirSpec, szDir, szIniFile);
  663.     }
  664.     }
  665.     return 0;
  666. }
  667.  
  668. //******************************************************************************
  669. //  Retrieve the directories associated with the configuration
  670. //******************************************************************************
  671. UpdateDirListOpt (HWND hWnd, BOOL bOpt)
  672. {
  673.   bSaveDir = bOpt;
  674.     return 0;
  675. }
  676.  
  677. //******************************************************************************
  678. //******************************************************************************
  679. int RetrieveConfig (HWND hDlg, BOOL bFlag)
  680. {
  681.   int nRC=0;
  682.   BOOL bXlat;
  683.  
  684.   memset (szScript, '\0', 5);
  685.   memset (szAccountPass, '\0', 5);
  686.   GetDlgItemText (hDlg, DLG_EDT_CONFIG, szConfig, 70);
  687.   GetDlgItemText (hDlg, DLG_EDT_HOST, szRemoteHost, 70);
  688.   GetDlgItemText (hDlg, DLG_EDT_USERID, szUserID, 15);
  689.   GetDlgItemText (hDlg, DLG_EDT_PASSWD, szPassWord, 50);
  690.   GetDlgItemText (hDlg, DLG_EDT_ACCOUNT, szAccountPass, 30);
  691.   GetDlgItemText (hDlg, DLG_EDT_SCRIPT, szScript, _MAX_PATH);
  692.   GetDlgItemText (hDlg, DLG_HOST_DIR, szInitDir, _MAX_PATH);
  693.   nRC = GetDlgItemInt (hDlg, DLG_HOST_TIMEOUT, &bXlat, FALSE);
  694.   if (!bXlat) nRC = 0; nRC = __min (nRC, 65);
  695.   uiTimeOut = ((nRC==0) ? 65 : (UINT) nRC ) * 1000;
  696.   bSavePWD = bFlag | IsDlgButtonChecked (hDlg,DLG_HOST_PASSWORD);
  697.   bSaveDir = IsDlgButtonChecked (hDlg,DLG_HOST_SAVEDIR);
  698.   bFireWall= IsDlgButtonChecked (hDlg,DLG_HOST_FIREWALL);
  699.   bAccount = (lstrlen (szAccountPass) > 0);
  700.   nAcctType = (int) SendDlgItemMessage (hDlg, DLG_ACCOUNTTYPE, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
  701.   nHostType = (int) SendDlgItemMessage (hDlg, DLG_HOST_CBHOSTTYPE, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
  702.   if ((!bAccount)||(nAcctType>4)) nAcctType = 0;
  703.   return 0;
  704. }
  705.  
  706. //******************************************************************************
  707. //******************************************************************************
  708. ProcessConfig (HWND hDlg)
  709. {
  710.   int nIndex = FindConfig (szConfig, TRUE);
  711.   switch (nIndex)
  712.   {
  713.     case -1: AddNewConfig(); break;
  714.     default: UpdateConfig (nIndex); break;
  715.   }
  716.   return 0;
  717. }
  718.  
  719. //******************************************************************************
  720. //******************************************************************************
  721. BOOL OnCmdDeleteHostConfig (HWND hDlg, WORD wCtlID, WORD wNotifyCode)
  722. {
  723.   int nIndex;
  724.   char szConfig[80];
  725.  
  726.   GetDlgItemText (hDlg, DLG_EDT_CONFIG, szConfig, 70);
  727.   nIndex = FindConfig (szConfig, TRUE);
  728.   if (nIndex!=-1) ClearConfig (nIndex);
  729.   memset (szConfig, '\0', sizeof (szConfig));
  730.   SetDlgItemText (hDlg, DLG_EDT_CONFIG, szConfig);
  731.   SetDlgItemText (hDlg, DLG_EDT_HOST,   szConfig);
  732.   SetDlgItemText (hDlg, DLG_EDT_USERID, szConfig);
  733.   SetDlgItemText (hDlg, DLG_EDT_PASSWD, szConfig);
  734.   SetDlgItemText (hDlg, DLG_HOST_DIR,   szConfig);
  735.   SetDlgItemInt (hDlg, DLG_HOST_TIMEOUT, uiTimeOut/1000, FALSE);
  736.   InitConfigLists (hDlg);
  737.   return TRUE;
  738. }
  739.  
  740. //******************************************************************************
  741. //******************************************************************************
  742. BOOL OnDlgHostInit (HWND hDlg)
  743. {
  744.   int nIndex;
  745.   
  746.   SendDlgItemMessage (hDlg, DLG_HOST_CBHOSTTYPE, CB_RESETCONTENT, (WPARAM) 0, (LPARAM) 0);
  747.   for (nIndex=0; nIndex<nHostTypes; nIndex++)
  748.   {
  749.     SendDlgItemMessage (hDlg, DLG_HOST_CBHOSTTYPE, CB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpHostTypes[nIndex]);
  750.   }
  751.   InitConfigLists (hDlg);
  752.   SetDlgItemText (hDlg, DLG_EDT_CONFIG, szConfig);
  753.   SetDlgItemText (hDlg, DLG_EDT_HOST, szRemoteHost);
  754.   SetDlgItemText (hDlg, DLG_EDT_USERID, szUserID);
  755.   SetDlgItemText (hDlg, DLG_EDT_PASSWD, szPassWord);
  756.   SetDlgItemText (hDlg, DLG_HOST_DIR, szInitDir);
  757.   SetDlgItemInt  (hDlg, DLG_HOST_TIMEOUT, uiTimeOut/1000, FALSE);
  758.   CheckDlgButton (hDlg, DLG_HOST_SAVEDIR, bSaveDir);
  759.   CheckDlgButton (hDlg, DLG_HOST_FIREWALL, bFireWall);
  760.   CheckDlgButton (hDlg, DLG_HOST_PASSWORD, FALSE);
  761.   if (lstrlen (szConfig)>0) SetDefaultConfigStuff (hDlg, szConfig);
  762.   else if (lstrlen (szRemoteHost)>0) SetDefaultHostStuff (hDlg, szRemoteHost);
  763.   SendDlgItemMessage (hDlg, DLG_EDT_HOST, WM_SETREDRAW, TRUE, 0l);
  764.   return TRUE;
  765. }
  766.  
  767. //******************************************************************************
  768. //******************************************************************************
  769. BOOL OnCmdEditConfig (HWND hDlg, WORD wCtlID, WORD wNotifyCode)
  770. {
  771.   int nIndex;
  772.  
  773.   switch (wNotifyCode)
  774.   {
  775.     case CBN_KILLFOCUS :
  776.     case CBN_EDITCHANGE: GetDlgItemText (hDlg, DLG_EDT_CONFIG, szConfig, 70);
  777.                          SetDefaultConfigStuff (hDlg, szConfig);
  778.                          return TRUE;
  779.     case CBN_SELCHANGE : if ((nIndex=(int) SendDlgItemMessage (hDlg, DLG_EDT_CONFIG, CB_GETCURSEL, 0, 0L))!=LB_ERR)
  780.                          {
  781.                            SendDlgItemMessage (hDlg, DLG_EDT_CONFIG, CB_GETLBTEXT, nIndex, (LPARAM)(LPCSTR) szConfig);
  782.                            SetDefaultConfigStuff (hDlg, szConfig);
  783.                            return TRUE;
  784.                          }
  785.   }
  786.   return FALSE;
  787. }
  788.  
  789. //******************************************************************************
  790. //******************************************************************************
  791. BOOL OnCmdAnonymous (HWND hDlg, WORD wCtlID, WORD wNotifyCode)
  792. {
  793.   SetDlgItemText (hDlg, DLG_EDT_USERID, szAnony);
  794.   SetDlgItemText (hDlg, DLG_EDT_PASSWD, szMailAddress);
  795.   return TRUE;
  796. }
  797.  
  798. //******************************************************************************
  799. //******************************************************************************
  800. BOOL OnCmdPassword (HWND hDlg, WORD wCtlID, WORD wNotifyCode)
  801. {
  802.   if (!IsDlgButtonChecked (hDlg, DLG_HOST_SAVE))
  803.      CheckDlgButton (hDlg, DLG_HOST_PASSWORD, FALSE);
  804.   return(FALSE);
  805. }
  806.  
  807. //******************************************************************************
  808. //******************************************************************************
  809. BOOL OnCmdSaveHostConfig (HWND hDlg, WORD wCtlID, WORD wNotifyCode)
  810. {
  811.   RetrieveConfig (hDlg, TRUE);
  812.   ProcessConfig (hDlg);
  813.   InitConfigLists (hDlg);
  814.   return TRUE;
  815. }
  816.  
  817. //******************************************************************************
  818. //******************************************************************************
  819. BOOL FAR PASCAL WS_HostMsgProc (HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
  820. {
  821.   switch(Message)
  822.   {
  823.     case WM_INITDIALOG: return OnDlgHostInit (hDlg);
  824.     case WM_CLOSE     : PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L); break;
  825.     case WM_COMMAND:
  826.     {
  827. #ifdef WIN32
  828.       WORD wCtlID =  LOWORD (wParam);
  829.       WORD wNotifyCode = HIWORD(wParam);
  830. #else
  831.       WORD wCtlID =  wParam;
  832.       WORD wNotifyCode = HIWORD(lParam);
  833. #endif
  834.       
  835.       switch (wCtlID)
  836.       {
  837.         case DLG_EDT_CONFIG   : return OnCmdEditConfig (hDlg, wCtlID, wNotifyCode); 
  838.         case DLG_HOST_ANONY   : return OnCmdAnonymous (hDlg, wCtlID, wNotifyCode);
  839.         case DLG_HOST_PASSWORD: return OnCmdPassword (hDlg, wCtlID, wNotifyCode);
  840.         case IDC_DELCFG       : return OnCmdDeleteHostConfig (hDlg, wCtlID, wNotifyCode);
  841.         case IDC_SAVCFG       : return OnCmdSaveHostConfig (hDlg, wCtlID, wNotifyCode);
  842.         case IDOK             : RetrieveConfig (hDlg, FALSE);
  843.                                 EndDialog (hDlg, TRUE); return TRUE;
  844.         case IDCANCEL         : EndDialog(hDlg, FALSE); return TRUE;
  845.         default               : return FALSE;
  846.       }
  847.     }
  848.     return TRUE;
  849.     default: return FALSE;
  850.   }
  851.   return TRUE;
  852. }
  853.  
  854. //********************************************************************
  855. //  Create a local Name for the file
  856. //********************************************************************
  857. MakeLocalName (LPSTR localname, LPSTR remotename)
  858. {
  859.   int nIndex;
  860.   char szRemote[_MAX_PATH], *lpRemote;
  861.   char szName[10], Ext[4], *s;
  862.  
  863.   //**********************************************************
  864.   // Scan past leading periods in string
  865.   //  Copy at most eight characters to szName
  866.   //**********************************************************
  867.   
  868.   lstrcpy (szRemote, remotename); 
  869.   lpRemote=szRemote;
  870.   if ((s=strchr (szRemote, ';'))!=NULL) *s='\0';
  871.   while (*lpRemote!=0 && *lpRemote=='.') lpRemote++;
  872.   for (nIndex=0; nIndex<8; nIndex++)
  873.   {
  874.     if (*lpRemote!=0 && *lpRemote!='.' && *lpRemote!=' ') szName[nIndex] = *lpRemote++;
  875.     else break;
  876.   }
  877.  
  878.   szName[nIndex]=0; 
  879.   Ext[0]=0;
  880.   
  881.   //**********************************************************
  882.   // Check if there are any second level names
  883.   //**********************************************************
  884.   if ((s=strchr(lpRemote,'.'))!=NULL) lpRemote=s;
  885.   
  886.   //**********************************************************
  887.   //  Scan past blanks or periods
  888.   //  Copy the next three characters at most to Extension
  889.   //**********************************************************
  890.   while ((*lpRemote!=0) && (*lpRemote=='.' || *lpRemote==' ')) lpRemote++;
  891.   if (*lpRemote!=0) 
  892.   {
  893.     for (nIndex=0; nIndex<3; nIndex++)
  894.     {
  895.       if (*lpRemote!=0) Ext[nIndex] = *lpRemote++;
  896.       else break;
  897.     }
  898.     Ext[nIndex]=0;
  899.   }
  900.   
  901.   //**********************************************************
  902.   //  Create the full local name of the local file
  903.   //**********************************************************
  904.   if (Ext[0]==0) lstrcpy (localname, szName);
  905.   else wsprintf (localname,"%s.%s",szName, Ext);
  906.  
  907.   if (lstrlen (localname)==0) 
  908.   {
  909.     lstrcpy (szName,"aaremote");
  910.     lstrcpy (localname, szName);
  911.   }
  912.  
  913.   if (bRecvUniq) 
  914.   {
  915.     CreateUniqueName (localname, szName, Ext);
  916.   }
  917.   return(TRUE);
  918. }
  919.  
  920. //********************************************************************
  921. // used if name is last thing on the line
  922. //********************************************************************
  923. LPSTR FindName(LPSTR szLine)
  924. {
  925.   int nIndex;
  926.   char *pStr;
  927.   static char szTrim[5] = " \r\n\t";
  928.   
  929.   nIndex = lstrlen (szLine);
  930.   
  931.   // strip trailing garbage from the line if there is any.
  932.   while ((nIndex>2) && (strchr (szTrim, szLine[nIndex-1])!=NULL))
  933.     szLine[nIndex--]=0;
  934.  
  935.   // now the name SHOULD be the last thing on the line
  936.   if((pStr=strrchr(szLine,' '))!=NULL ||
  937.      (pStr=strrchr(szLine,0x09))!=NULL) 
  938.   {
  939.     while(*pStr && (*pStr==' ' || *pStr==0x09)) pStr++;
  940.     return(pStr);
  941.   }
  942.   return(szLine);
  943. }
  944.  
  945. //********************************************************************
  946. //  Process Dir Line for SuperTCP, Chameleon, NCSA servers
  947. //********************************************************************
  948. void ReadDirLineSuperTCP (LPSTR lpStr)
  949. {
  950.   LPSTR pStr;
  951.  
  952.   if (strstr (lpStr,"<DIR>")!=NULL) 
  953.   {
  954.     if ((pStr=strchr(lpStr,' '))!=NULL) *pStr=0;
  955.     if (lstrcmp (lpStr,".")!=0 && lstrcmp (lpStr,"..")!=0)
  956.        SendMessage (hLbxRDir, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  957.   } 
  958.   else 
  959.   {
  960.     if ((pStr=strchr (lpStr,' '))!=NULL) *pStr=0;
  961.     if (lpStr[0]!=0)
  962.        SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  963.   }
  964. }
  965.  
  966. //********************************************************************
  967. //  Process Dir Line for QVT/Net server
  968. //********************************************************************
  969. void ReadDirLineQVT (LPSTR lpStr)
  970. {
  971.   int nLen = lstrlen (lpStr);
  972.   
  973.   if (lpStr[nLen-1]=='/' || lpStr[nLen-1]=='\\')
  974.   {
  975.     lpStr[nLen-1]=0;
  976.     if (lstrcmp(lpStr,".")!=0 && lstrcmp (lpStr,"..")!=0)
  977.         SendMessage (hLbxRDir, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  978.   } 
  979.   else
  980.   {
  981.     SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  982.   }
  983. }
  984.  
  985. //********************************************************************
  986. //  Process Dir Line for IBM VM servers
  987. //********************************************************************
  988. void ReadDirLineIBMVM (LPSTR lpStr)
  989. {
  990.   lpStr[12]=0;
  991.   SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  992. }
  993.  
  994. //********************************************************************
  995. //  Process Dir Line for IBM MVS servers
  996. //********************************************************************
  997. void ReadDirLineIBMMVS (LPSTR lpStr)
  998. {
  999.   if (strstr (lpStr, "Lrecl")!=NULL) return;
  1000.   if (lstrlen (lpStr+54)>0)
  1001.      SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) (lpStr+54));
  1002. }
  1003.  
  1004. //********************************************************************
  1005. //  Process Dir Line for VMS servers
  1006. //********************************************************************
  1007. void ReadDirLineVMS (LPSTR lpStr)
  1008. {
  1009.   int nLen = lstrlen (lpStr);
  1010.   LPSTR lp, s;
  1011.  
  1012.   if (*lpStr==' ') return;
  1013.   if ((s=strchr(lpStr,';'))==NULL) return;
  1014.                   
  1015.   s++; 
  1016.   while (isdigit (*s)) s++;
  1017.   *s=0;
  1018.   if ((nLen>4) && ((lp=strstr (lpStr,".DIR"))!=NULL))
  1019.   {
  1020.     *lp = 0;
  1021.     SendMessage (hLbxRDir, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  1022.   } 
  1023.   else
  1024.   {
  1025.     SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  1026.   }
  1027. }
  1028.  
  1029. //********************************************************************
  1030. //  Process Dir Line for PCTCP servers
  1031. //********************************************************************
  1032. void ReadDirLinePCTCP (LPSTR lpStr)
  1033. {
  1034.   LPSTR lp;
  1035.  
  1036.   lpStr[30]=0; 
  1037.   lp=FindName(lpStr);
  1038.   if (strncmp (lpStr, "<dir>", 5)==0) 
  1039.   {
  1040.     if (lstrcmp(lp,".")!=0 && lstrcmp(lp,"..")!=0)
  1041.          SendMessage (hLbxRDir, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lp);
  1042.   } 
  1043.   else
  1044.   {
  1045.     SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LPARAM)(LPCSTR) lp);
  1046.   }
  1047. }
  1048.  
  1049. //********************************************************************
  1050. //  Process Dir Line for SuperTCP, Chameleon, NCSA servers
  1051. //********************************************************************
  1052. void ReadDirLineIBMTCP (LPSTR lpStr)
  1053. {
  1054.   LPSTR lp;
  1055.  
  1056.   lp = FindName (lpStr);
  1057.   if (strstr (lpStr," DIR ")!=NULL) 
  1058.   {
  1059.     if (lstrcmp(lp,".")!=0 && lstrcmp(lp,"..")!=0)
  1060.        SendMessage (hLbxRDir, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lp);
  1061.   } 
  1062.   else
  1063.   {
  1064.     SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lp);
  1065.   }
  1066. }
  1067.  
  1068. //********************************************************************
  1069. //  Process Dir Line for SuperTCP, Chameleon, NCSA servers
  1070. //********************************************************************
  1071. void ReadDirLineNOS (LPSTR lpStr)
  1072. {
  1073.   LPSTR pStr;
  1074.   int nLen, nRC;
  1075.  
  1076.   if (strstr (lpStr,"Disk size")!=NULL) return;
  1077.              
  1078.   nLen=lstrlen (lpStr);
  1079.   lpStr[13]=0; 
  1080.   nRC=13;
  1081.   while (nLen>0 && lpStr[nLen-1]==' ') lpStr[--nLen]=0;
  1082.   if (*lpStr!=0) 
  1083.   {
  1084.     if (lpStr[nLen-1]=='/' || lpStr[nLen-1]=='\\')
  1085.     {
  1086.       lpStr[nLen-1]=0;
  1087.       if (lstrcmp (lpStr,".")!=0)
  1088.         SendMessage (hLbxRDir, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  1089.     } 
  1090.     else
  1091.     {
  1092.       SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpStr);
  1093.     }
  1094.   }
  1095.   pStr=lpStr+41; 
  1096.   nRC=13; 
  1097.   pStr[nRC]=0;
  1098.   while ((nRC=lstrlen(pStr))>0 && pStr[nRC-1]==' ') pStr[nRC-1]=0;
  1099.   if (*pStr=='\0') return;
  1100.  
  1101.   nLen = lstrlen (pStr);
  1102.   if (pStr[nLen-1]=='/' || pStr[nLen-1]=='\\')
  1103.   {
  1104.     pStr[nLen-1]=0;
  1105.     if (lstrcmp (pStr,".")!=0 && lstrcmp (pStr,"..")!=0)
  1106.        SendMessage (hLbxRDir, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) pStr);
  1107.   } 
  1108.   else
  1109.   {
  1110.     SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) pStr);
  1111.   }
  1112. }
  1113.  
  1114. //********************************************************************
  1115. //  Process Dir Line for SuperTCP, Chameleon, NCSA servers
  1116. //********************************************************************
  1117. void ReadDirLineUNIX (LPSTR lpStr)
  1118. {
  1119.   LPSTR pStr;
  1120.  
  1121.   // assume UNIX ls format
  1122.   // if line starts with 'd' its a directory
  1123.   
  1124.   pStr = FindName (lpStr);
  1125.   if (lpStr[0]=='d')
  1126.   {
  1127.     if (lstrcmp (pStr,".")!=0 && lstrcmp (pStr,"..")!=0)
  1128.       SendMessage(hLbxRDir,LB_ADDSTRING,0,(LPARAM)(LPCSTR) pStr);
  1129.   } 
  1130.   else if (lpStr[0]=='l')
  1131.   {
  1132.     SendMessage (hLbxRDir,LB_ADDSTRING,0,(LPARAM)(LPCSTR) pStr);
  1133.     SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) pStr);
  1134.   } 
  1135.   else
  1136.   {
  1137.     // if line starts with - or f its a file
  1138.     if (nHostType==HOST_SINTFTPD || strchr ("-f", lpStr[0])!=NULL) 
  1139.     {
  1140.       SendMessage (hLbxRFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) pStr);
  1141.     }
  1142.   }
  1143. }
  1144.  
  1145. //********************************************************************
  1146. //  Get the Remote directory listing
  1147. //********************************************************************
  1148. int GetRemoteDirForWnd (HWND hWnd)
  1149. {
  1150.   char *pStr;
  1151.   FILE *fd;
  1152.   int nRC, nLen;
  1153.  
  1154.   //***************************************************************
  1155.   // clean out the old contents of the list boxes
  1156.   //***************************************************************
  1157.   SendMessage (hLbxRDir,   LB_RESETCONTENT, 0, 0);
  1158.   SendMessage (hLbxRFiles, LB_RESETCONTENT, 0, 0);
  1159.  
  1160.   //***************************************************************
  1161.   // can't do much if we aren't connected
  1162.   //***************************************************************
  1163.   if (!bConnected) 
  1164.   {
  1165.     SendMessage (hTxtRDir, WM_SETTEXT,0,(LPARAM)(LPCSTR) "");
  1166.     if (bHELP) DoAddLine ("Connection Closed"), bHELP = FALSE;
  1167.     return 0;
  1168.   }
  1169.  
  1170.   //***************************************************************
  1171.   // For the first time round, do the Help command now to avoid
  1172.   // Undecipherable in the Directory window.
  1173.   //***************************************************************
  1174.   if (!bHELP) ReadProcessHelp (hWnd, ctrl_socket);
  1175.   
  1176.   //***************************************************************
  1177.   // get the remote directory name
  1178.   //***************************************************************
  1179.   lstrcpy (szString, szUndecipher);
  1180.   nRC = DoPWD (ctrl_socket);
  1181.   if (nRC==FTP_COMPLETE) 
  1182.   {
  1183.     if ((pStr=strchr (szMsgBuf,'"'))!=NULL) strncpy (szString,++pStr,180);
  1184.     else ConvertSourceDir (szMsgBuf, szString, 100);
  1185.     if ((pStr=strchr (szString,'"'))!=NULL) *pStr=0;
  1186.     else szString[180]=0;
  1187.   }
  1188.  
  1189.   //***************************************************************
  1190.   // DLG_RDIRECTORY (directory name)
  1191.   //***************************************************************
  1192.   SendMessage (hTxtRDir, WM_SETTEXT, 0, (LPARAM)(LPCSTR) szString);
  1193.   AddDirToList (hWnd, LST_RDIRLST, szString);
  1194.   SendDlgItemMessage (hWnd, LST_RDIRLST, CB_SELECTSTRING, (WPARAM) 0, (LPARAM)(LPCSTR) szString);
  1195.  
  1196.   //***************************************************************
  1197.   // go get the current remote directory listing in tmpfile.tmp
  1198.   // get the file type, check for all files, if not, append to the
  1199.   // LIST request about to be issued to the remote host
  1200.   //***************************************************************
  1201.   lstrcpy (szString, "LIST");
  1202.   if ((wSortType==IDM_SORTBYDATE) && (nHostType==HOST_UNIX || nHostType==HOST_AUTO))
  1203. //  if (wSortType==IDM_SORTBYDATE)
  1204.   {
  1205.     lstrcat (szString, " -lt");
  1206.   }
  1207.   nLen = lstrlen (szString);
  1208.   szString[nLen++] = '\0';
  1209.   SetDebugWindowText ("WinFTP List");
  1210.   SendDlgItemMessage (hWnd, EDT_RFILETYPE, WM_GETTEXT, (WPARAM) 80, (LPARAM)(LPCSTR)(szString+nLen));
  1211.   if ((lstrlen (szString+nLen)>0) && (lstrcmp (szString+nLen,"*")!=0)) szString[nLen-1] = ' ';
  1212.   nRC = DoDirList (ctrl_socket, szString);
  1213.  
  1214.   SetDebugWindowText (lpDebugWindow);
  1215.   SendMessage (hLbxRDir, LB_ADDSTRING,0, (LPARAM)(LPCSTR) "..");
  1216.   if (nRC!=FTP_COMPLETE)
  1217.   {
  1218.     DoPrintf ("Directory List Error (Code %u)", nRC);
  1219.     return 0;
  1220.   }
  1221.  
  1222.   if ((fd=fopen (szCurrentDir,"r"))==NULL)
  1223.   {
  1224.     DoAddLine ("Couldn't open TempDirFile for reading.");
  1225.     return 0;
  1226.   }
  1227.  
  1228.   while (fgets (szString,180,fd)!=NULL)
  1229.   {
  1230.     if ((pStr=strchr (szString,'\n'))!=NULL) *pStr=0;
  1231.     switch (nHostType) 
  1232.     {
  1233.       case HOST_SUPER       : ReadDirLineSuperTCP (szString); break;
  1234.       case HOST_CHAMELEON   : ReadDirLineSuperTCP (szString); break;
  1235.       case HOST_NCSA        : ReadDirLineSuperTCP (szString); break;
  1236.       case HOST_QVT         : ReadDirLineQVT (szString); break;
  1237.       case HOST_IBM_VM      : ReadDirLineIBMVM (szString); break;
  1238.       case HOST_MVS         : ReadDirLineIBMMVS (szString); break;
  1239.       case HOST_VMS_UCX     : ReadDirLineVMS (szString); break;
  1240.       case HOST_VMS_MULTINET: ReadDirLineVMS (szString); break;
  1241.       case HOST_PCTCP       : ReadDirLinePCTCP (szString); break;
  1242.       case HOST_IBM_TCP     : ReadDirLineIBMTCP (szString); break;
  1243.       case HOST_NOS         : ReadDirLineNOS (szString); break;
  1244.       case HOST_SINTFTPD    : ReadDirLineUNIX (szString); break;
  1245.       case HOST_U5000       : ReadDirLineUNIX (szString); break;
  1246.       case HOST_UNIX        : ReadDirLineUNIX (szString); break;
  1247.       default               : ReadDirLineUNIX (szString); break;
  1248.     }
  1249.   }
  1250.   fclose(fd);
  1251.   return 0;
  1252. }
  1253.  
  1254. extern BOOL bCanMKD,bCanRMD,bCanREN,bCanDELE;
  1255.  
  1256. //********************************************************************
  1257. //  Show Flag Settings
  1258. //********************************************************************
  1259. void ShowOurFlags()
  1260. {
  1261.   DoPrintf("MKD=%u RMD=%u REN=%u DEL=%u HostType=%u",
  1262.     bCanMKD,bCanRMD,bCanREN,bCanDELE,nHostType);
  1263. }
  1264.  
  1265. //********************************************************************
  1266. //  Process Help Info
  1267. //********************************************************************
  1268. int ReadProcessHelp (HWND hWnd, SOCKET ctrl_socket)
  1269. {
  1270.   int iRetCode;
  1271.   BOOL bCanSYST;
  1272.  
  1273.   bCanMKD=bCanRMD=bCanREN=bCanDELE=bCanSYST=FALSE;
  1274.  
  1275.   if (SendPacket (ctrl_socket,"HELP")!=-1) 
  1276.   {
  1277.     SetDebugWindowText ("WSFTP Help");
  1278.     iRetCode=ReadLine(ctrl_socket);
  1279.     if((iRetCode/100)==5 && nHostType==0) nHostType = HOST_NOS;
  1280.     else 
  1281.     {
  1282.       if (nHostType==HOST_AUTO) 
  1283.       {
  1284.         if (strstr(szMsgBuf,"NCSA")!=NULL || strstr(szMsgBuf,"CUTCP")!=NULL) nHostType=HOST_NCSA;
  1285.         else if (strncmp(szMsgBuf,"214-PC FTP server",17)==0 || strstr(szMsgBuf,"QVT")!=NULL)
  1286.                 nHostType=HOST_QVT;
  1287.       }
  1288.       while((iRetCode!=421) && ((iRetCode/100)!=2 || szMsgBuf[3]=='-')) 
  1289.       {
  1290.         if(strstr(szMsgBuf,"MKD")!=NULL) bCanMKD=TRUE;
  1291.         if(strstr(szMsgBuf,"RMD")!=NULL) bCanRMD=TRUE;
  1292.         if(strstr(szMsgBuf,"RNFR")!=NULL) bCanREN=TRUE;
  1293.         if(strstr(szMsgBuf,"DELE")!=NULL) bCanDELE=TRUE;
  1294.         if(strstr(szMsgBuf,"SYST")!=NULL) bCanSYST=TRUE;
  1295.         iRetCode=ReadLine(ctrl_socket);
  1296.       }
  1297.     }
  1298.   }
  1299.   SetButtonEnabledStatus (BTN_RMKDIR, bCanMKD);
  1300.   SetButtonEnabledStatus (BTN_RRMDIR, bCanRMD);
  1301.   SetButtonEnabledStatus (BTN_RRENAME, bCanREN);
  1302.   SetButtonEnabledStatus (BTN_RDELETE, bCanDELE);
  1303.   bHELP=TRUE;
  1304.   
  1305.   if (bCanSYST) DoSystemCommand (ctrl_socket);
  1306.   else if (nHostType==HOST_AUTO) nHostType=HOST_UNIX;
  1307.   SetDebugWindowText (lpDebugWindow);
  1308.   return iRetCode;
  1309. }
  1310.  
  1311. //************************************************************************
  1312. //  Convert Directory name to VMS style directory name
  1313. //************************************************************************
  1314. ConvertToVMSDir (LPSTR lpDir, int nSiz)
  1315. {
  1316.   char szTmp[120];
  1317.  
  1318.   (lstrcmp (lpDir,"..")!=0) ? ((long) wsprintf (szTmp, "[.%s]", lpDir)) : ((long) lstrcpy (szTmp, "[-]"));
  1319.   if (lstrlen (szTmp)<nSiz) lstrcpy (lpDir, szTmp);
  1320.   return 0;
  1321. }
  1322.  
  1323. //************************************************************************
  1324. //  Convert Directory name to VMS style directory name
  1325. //************************************************************************
  1326. ConvertFromVMSDir (LPSTR lpBuf, LPSTR lpDir, int nSiz)
  1327. {
  1328.   char *lp;
  1329.  
  1330.   lp = strstr (lpBuf, ":[");    //  Look for the Disk:[dir] format
  1331.   if (lp==NULL) return 0;       //  If not found, nothing can be done
  1332.   while ((lp!=lpBuf) && (*lp!=' ')) lp--;
  1333.   if (*lp==' ') lp++;
  1334.  
  1335. #ifdef WIN32
  1336.   lstrcpy (lpDir, lp);
  1337. #else
  1338.   lstrcpyn (lpDir, lp, nSiz-1);
  1339. #endif
  1340.   
  1341.   lp = strchr (lpDir, ' ');
  1342.   if (lp!=NULL) *lp = '\0';
  1343.   return 0;
  1344. }
  1345.  
  1346. //************************************************************************
  1347. //  Convert Directory name to VMS style directory name
  1348. //************************************************************************
  1349. ConvertFromDefaultDir (LPSTR lpBuf, LPSTR lpDir, int nSiz)
  1350. {
  1351.   LPSTR lp;
  1352.   char szBuf[_MAX_PATH];
  1353.  
  1354.   lp = strchr (lpBuf, '"');    //  Look for the Disk:[dir] format
  1355.   if (lp==NULL) return 0;       //  If not found, nothing can be done
  1356.   lp++;
  1357.   lstrcpy (szBuf, lp);
  1358.   lp = strchr (szBuf, '"');
  1359.   if (lp==NULL) return 0;
  1360.   *lp = '\0';
  1361.  
  1362. #ifdef WIN32
  1363.   lstrcpy (lpDir, szBuf);
  1364. #else
  1365.   lstrcpyn (lpDir, szBuf, nSiz-1);
  1366. #endif
  1367.   
  1368.   lp = strchr (lpDir, ' ');
  1369.   if (lp!=NULL) *lp = '\0';
  1370.   return 0;
  1371. }
  1372.  
  1373. //************************************************************************
  1374. //  Convert to the appropriate host directory name format
  1375. //************************************************************************
  1376. ConvertTargetDir (LPSTR lpDir, int nSiz)
  1377. {
  1378.   switch (nHostType)
  1379.   {
  1380.     case HOST_VMS_MULTINET:
  1381.     case HOST_VMS_UCX     : ConvertToVMSDir (lpDir, nSiz); break;
  1382.   }
  1383.   return 0;  
  1384. }
  1385.  
  1386. //************************************************************************
  1387. //  Convert to the appropriate host directory name format
  1388. //************************************************************************
  1389. ConvertSourceDir (LPSTR lpBuf, LPSTR lpDir, int nSiz)
  1390. {
  1391.   switch (nHostType)
  1392.   {
  1393.     case HOST_VMS_MULTINET: 
  1394.     case HOST_VMS_UCX     : ConvertFromVMSDir (lpBuf, lpDir, nSiz); break;
  1395.     default               : ConvertFromDefaultDir (lpBuf, lpDir, nSiz); break;
  1396.   }
  1397.   return 0;  
  1398. }
  1399.  
  1400.  
  1401.